<?php
function hfr_admin() {
?>
	<div class="hfr-content">
		<?php include ('admin/header.php');?>
		<?php include ('admin/content.php');?>
		<?php include ('admin/footer.php');?>
	</div>
	<?php
	echo ob_get_clean();
}

function hfr_add_options_link() {
	add_menu_page('Hatforrent Management', 'Hatforrent', 'manage_options', 'hatforrent', 'hfr_admin', "image/hatforrent.jpg");
	$page1 = add_submenu_page('hatforrent', 'Hatforrent Plugin Overview', 'Overview', 'manage_options', 'hatforrent', 'hfr_admin');
	$page2 = add_submenu_page('hatforrent', 'Hatforrent Plugin Config', 'Setup', 'manage_options', 'hfr_setup', 'hfr_admin');
	if (get_option("hfr_setup") == 1) {
		$page3 = add_submenu_page("hatforrent", 'Source Manager', 'Source Manager', 'manage_options', 'hfr_source_manager', 'hfr_admin');
		$page4 = add_submenu_page("hatforrent", 'Add Source', 'Add Source', 'manage_options', 'hfr_source_manager&act=new', 'hfr_admin');
		$page5 = add_submenu_page("hatforrent", 'Payment Renew', 'Payment Renew', 'manage_options', 'hfr_payment', 'hfr_admin');
	}
	$page6 = add_submenu_page("hatforrent", 'Contact', 'Contact', 'manage_options', 'hfr_contact', 'hfr_admin');
	
	
	add_action('admin_print_scripts', 'hfr_load_scripts');
	
	add_action('admin_print_scripts-' . $page1, 'hfr_load_overview_scripts');
	add_action('admin_print_scripts-' . $page2, 'hfr_load_setup_scripts');
	add_action('admin_print_scripts-' . $page3, 'hfr_load_source_manager_scripts');
	add_action('admin_print_scripts-' . $page5, 'hfr_load_payment_scripts');
	add_action('admin_print_scripts-' . $page6, 'hfr_load_contact_scripts');
}

function hfr_load_scripts() {
	wp_enqueue_style('hfr-styles1', plugin_dir_url( __FILE__ ) . 'assets/css/hfr-styles.css');
	wp_enqueue_style('hfr-styles2', plugin_dir_url( __FILE__ ) . 'assets/css/hfr-bootstrap.css');
	wp_enqueue_script('hft-script1', plugin_dir_url( __FILE__ ) . 'assets/js/hfr-bootstrap.js', array('jquery','jquery-ui-core','jquery-ui-sortable', 'jquery-ui-dialog','jquery-ui-tabs'));
}

function hfr_load_overview_scripts() {
	
}

function hfr_load_setup_scripts() {
	
}

function hfr_load_source_manager_scripts() {
	if (isset($_GET['page']) && $_GET['page'] == 'hfr_source_manager' && isset($_GET['act']) && ($_GET['act'] == 'new' || $_GET['act'] == 'edit')) {
		wp_enqueue_style( 'hfr-jquery-ui', plugin_dir_url( __FILE__ ) . 'assets/css/hfr-jquery-ui.css'); 
		
		wp_enqueue_script('hft-base64-script', plugin_dir_url( __FILE__ ) . 'assets/js/jquery.base64.js', array('jquery', 'jquery-ui-core', 'jquery-ui-slider'));
		//wp_enqueue_script('hft-ace-script', 'http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js');
		
		// ace editor
		wp_register_script( 'ace_editor', plugin_dir_url( __FILE__ ) . 'assets/js/ace/ace.js', array() );
		wp_enqueue_script( 'ace_editor' );
	    
		// ace css mode
		wp_register_script( 'ace_mode_css', plugin_dir_url( __FILE__ ) . 'assets/js/ace/mode-css.js', array( 'ace_editor' ) );
		wp_enqueue_script( 'ace_mode_css' );
	    
		// ace php mode
		wp_register_script( 'ace_mode_php', plugin_dir_url( __FILE__ ) . 'assets/js/ace/mode-php.js', array( 'ace_editor' ) );
		wp_enqueue_script( 'ace_mode_php' );
		
	    // ace javascript mode
		wp_register_script( 'ace_mode_javascript', plugin_dir_url( __FILE__ ) . 'assets/js/ace/mode-javascript.js', array( 'ace_editor' ) );
		wp_enqueue_script( 'ace_mode_javascript' );
		
		// ace worker javascript
		wp_register_script( 'ace_worker_javascript', plugin_dir_url( __FILE__ ) . 'assets/js/ace/worker-javascript.js', array( 'ace_editor' ) );
		wp_enqueue_script( 'ace_worker_javascript' );
		
		// ace chrome theme
		wp_register_script( 'ace_theme_chrome', plugin_dir_url( __FILE__ ) . 'assets/js/ace/theme-chrome.js', array( 'ace_editor' ) );
		wp_enqueue_script( 'ace_theme_chrome' );
		
	} elseif (isset($_GET['page']) && $_GET['page'] == 'hfr_source_manager') {
		wp_enqueue_script('hft-script2', plugin_dir_url( __FILE__ ) . 'assets/js/hfr-source-manager.js', array('jquery'));
	}
}

function hfr_load_payment_scripts() {
	
}

function hfr_load_contact_scripts() {
	
}

add_action('init', 'hfr_do_output_buffer');
function hfr_do_output_buffer() {
        ob_start();
}
add_action('admin_menu', 'hfr_add_options_link');



function hfr_smushit_filter_timeout_time($time) {
	$time = 25; //new number of seconds
	return $time;
}

add_filter( 'http_request_timeout', 'hfr_smushit_filter_timeout_time');
